<?php
namespace app\xiangmu\controller;
class Userbill extends Base {
    //列表
    public function lists() {
        if (is_post()) {
            $d = $this->post;
            $map = [];
            if($d['keyword']){ $map[] = ['and','b.username','like',"%{$d['keyword']}%"]; }
            if($d['type']){ $map[] = ['and','a.type','=',$d['type']]; }
            if($d['min_time']) $map[] = ['and','a.create_time','>=',strtotime($d['min_time'])];
            if($d['max_time']) $map[] = ['and','a.create_time','<=',strtotime($d['max_time'])];
            $w = where($map);
            $rs = $this->db->query("select a.*,b.username from user_bill a left join user b on a.user_id=b.id $w[0] order by a.id desc" . limit($d['page'], $d['limit']), $w[1], '', true);
            if ($rs) {
                foreach ($rs[0] as $key => $val) {
                  $rs[0][$key]['type'] = c("type.user_bill_type.{$val['type']}");
                  $rs[0][$key]['create_time'] = date('Y-m-d H:i', $val['create_time']);
                }
                suc($rs[0], $rs[1]);
            } else {
                suc([], 0);
            }
        }
        $this->fetch([],'','layadmin');
    }
}
